#include "func.h"

void Stack::Init()
{
	_a = nullptr;
	_top = _capacity = 0;
}

void Stack::Push(int x)
{
	if (_top == _capacity)
	{
		int newcapacity = _a == nullptr ? 4 : _capacity * 2;
		_a = (int*)realloc(_a, sizeof(int) * newcapacity);
		if (_a == nullptr)
		{
			perror("malloc failed");
			exit(-1);
		}
		_capacity = newcapacity;
	}
	_a[_top++] = x;
}

void Stack::Pop()
{
	_top--;
}

void Stack::Print()
{
	for (int i=0; i<_top; i++)
	{
		cout << _a[i] << " ";
	}
}

//void Date::Init(int year, int month, int day)
//{
//	_year = year;
//	_month = month;
//	_day = day;
//}

void Date::Print()
{
	cout << _year << '-' << _month << '-' << _day << endl;
}

Date::Date(int year, int month, int day)
	:_day(day)
{
	_year = year;
	_month = month;
	_day = day;
}